package zhaotest;

import com.tencent.trustsql.sdk.ErrorNum;
import com.tencent.trustsql.sdk.TrustSDK;
import com.tencent.trustsql.sdk.demo.command.Command;
import com.tencent.trustsql.sdk.exception.TrustSDKException;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;

public class VerifyRenSignCommand implements Command {

	@Override
	public String execute(String... args) throws Exception {
		if (args == null || args.length < 4 || StringUtils.isEmpty(args[1]) || StringUtils.isEmpty(args[2])) {
			throw new TrustSDKException(ErrorNum.INVALID_PARAM_ERROR.getRetCode(),
					ErrorNum.INVALID_PARAM_ERROR.getRetMsg());
		}

		String pubKey = args[1];
		String data = args[2];
		String sign = args[3];
		try {
			boolean flag = TrustSDK.verifyString(pubKey, data, sign);
			System.out.println("flag:" + flag);
			return Boolean.toString(flag);
		} catch (Exception e) {
			throw new TrustSDKException(ErrorNum.INVALID_PARAM_ERROR.getRetCode(),
					ErrorNum.INVALID_PARAM_ERROR.getRetMsg());
		}
	}

	public static void main(String[] args) throws TrustSDKException, DecoderException {
		boolean flag = TrustSDK.verifyRenSign("Aj56Q9WYRtRhv7EVGmm29mOmLYSSPdMaoH9lchnGJM1x",
				Hex.decodeHex("21a4af3ecc3095f4c5fc95fb9c9e05f426bcb8776ce0ede145136a899d34459d".toCharArray()),
				"MEQCIDc59VOF9udi3yj5OoqOuNkCzzfp31UGolo6Rq0f5IZzAiB4cjsc9QnIYt503/R3JGyTtYUJCFbmkLdd/K37Iq2PTA==");
		System.out.println("flag:" + flag);



	}

}
